####
#### Eroll Kuhn & Rahsaan Maxwell
#### Main Plot
### 10.2020


rm(list=ls())

library(tidyverse)
library(gridExtra)

# read in frame
df <- read.csv(".../4.Main Models/Output/B.Tables/Clean_Combined.csv")


# pre-processing
df <- data.frame(df)

df <- subset(df,df$IV !="% from Arabic-Speaking Country")
df$Numeric <- ifelse(df$IV=="% Co-National",df$Numeric-1,df$Numeric)


png(".../4.Main Models/Output/D.Figure/CoefPlot_Index_OLS.png",
    width=10,height=6,units='in',res=300)
ggplot(df) +
  geom_pointrange(aes(x=Numeric,y=Coef,ymin=Lower95,ymax=Upper95,shape=as.factor(Spec)),lwd=0.25) +
  geom_pointrange(aes(x=Numeric,y=Coef,ymin=Lower90,ymax=Upper90,shape=as.factor(Spec)),lwd=0.5) +
  theme_bw() +
  geom_hline(yintercept = 0, lty = 2) +
  ylab("Effect on Feeling Welcome") +
  xlab("") +
  xlim(1,4) +
  theme(legend.direction = "horizontal",
        legend.position = "bottom",
        panel.grid.major.x = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(angle = 15, hjust = 1,size = 12),
        axis.text.y = element_text(size=12),
        legend.text = element_text(size = 12)) +
  scale_x_discrete(limits=c(1.5,2.5,3.5,4.5),
                   labels = c("% Foreign-Born",
                              "% Non-EU",
                              "% Co-National")) +
  scale_shape_discrete(name = "Model Specification", 
                       labels = c("Baseline","Individual Controls Only",
                                  "Full Model: Theory Driven Selection of Contextual Controls ",
                                  "Full Model: PDS Selection of Contextual Controls")) +
  guides(shape=guide_legend(nrow=2)) 
dev.off()   



##################
# Disagg by Syrians
rm(list=ls())

library(tidyverse)
library(gridExtra)

# read in frame
df <- read.csv(".../4.Main Models/Output/B.Tables/Clean_Combined_Disagg.csv")


# pre-processing
df <- data.frame(df)

df$facet_lab <- ifelse(df$IV=="% Foreign-Born",1,
                       ifelse(df$IV=="% Non-EU",2,
                                     ifelse(df$IV=="% Co-National",3,NA)))

df$facet_lab <- factor(df$facet_lab,
                       levels = c(1,2,3),
                       labels = c("% Foreign-Born", 
                                  "% Non-EU Foreign-Born",
                                  "% Co-National"))

png(".../4.Main Models/Output/D.Figure/CoefPlot_Disagg_OLS.png",
    width=10,height=6,units='in',res=300)
ggplot(df) +
  geom_pointrange(aes(x=Numeric,y=Coef,ymin=Lower95,ymax=Upper95,shape=Subsample),lwd=0.25) +
  geom_pointrange(aes(x=Numeric,y=Coef,ymin=Lower90,ymax=Upper90,shape=Subsample),lwd=0.5) +
  theme_bw() +
  facet_wrap(~facet_lab) +
  xlim(1,2) +
  geom_hline(yintercept = 0,lty=2) +
   ylab("Effect on Demographic Context on Feeling Welcome") +
  xlab("") +
  theme(legend.direction = "horizontal",
        legend.position = "bottom",
        panel.grid.major.x = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size=8, angle = 15, hjust = 1),
        axis.text.y = element_text(size=8),
        legend.text = element_text(size = 12)) +
  scale_x_discrete()
dev.off() 